package com.itheima.factory;

import java.util.ResourceBundle;

public class BeanFactory {

    public static Object getBean(String beanId) {
        try {
            //1. 读取配置文件
            ResourceBundle resourceBundle = ResourceBundle.getBundle("beans");

            //2. 根据beanId获取到类的全限定名
            String className = resourceBundle.getString(beanId);

            //3. 反射创建对象
            Class<?> clazz = Class.forName(className);
            Object instance = clazz.newInstance();

            //4. 返回结果
            return instance;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }
}
